package one.stand.controller;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import one.stand.model.ResultModel;
import one.stand.request.live.*;
import one.stand.response.live.ShortVideoResponse;
import one.stand.service.AttentionUserService;
import one.stand.service.ShortVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 短视频业务
 * @author luoyang
 * @date 2020/5/20 11:56
 */
@RestController
@RequestMapping("shortVideo")
@Slf4j
public class ShortVideoController extends BaseController{


    @Autowired
    private ShortVideoService shortVideoService;

    @Autowired
    private AttentionUserService addAttentionUser;

    /**
     * 添加短视频
     * @param request
     * @return
     */
    @PostMapping("add")
    public ResultModel<Boolean> add(@RequestBody @Valid ShortVideoForm request){
        log.info("addVideo:{}",request);
        return shortVideoService.add(request);
    }

    /**
     * 更新
     * @param request
     * @return
     */
    @PostMapping("update")
    public ResultModel<Boolean> update(@RequestBody @Valid ShortVideoForm request){
        log.info("update:{}",request);
        return shortVideoService.update(request);
    }

    /**
     * 更新视频浏览数据
     * @param request
     * @return
     */
    @PostMapping("updateData")
    public ResultModel<Boolean> updateData(@RequestBody @Valid ShortVideoDataForm request){
        log.info("updateData:{}",request);
        return shortVideoService.updateData(request);
    }

    /**
     *  关注或点赞
     * @param request
     * @return
     */
    @PostMapping("addAttentionUser")
    public ResultModel<Boolean> addAttentionUser(@RequestBody @Valid AttentionUserFrom request){
        log.info("addAttentionUser:{}",request);
        return addAttentionUser.addAttentionUser(request);
    }

    /**
     * 查询
     * @param request
     * @return
     */
    @PostMapping("queryById")
    public ResultModel<ShortVideoResponse> queryById(@RequestBody @Valid ShortVideoQuery request){
        log.info("queryById:{}",request);
        return shortVideoService.queryById(request);
    }

    /**
     * 删除
     * @param request
     * @return
     */
    @PostMapping("deleteById")
    public ResultModel<Boolean> deleteById(@RequestBody @Valid ShortVideoQuery request){
        log.info("deleteById:{}",request);
        return shortVideoService.deleteById(request.getVideoId());
    }


    /**
     * 分页查询
     * @param request
     * @return
     */
    @PostMapping("queryPage")
    public ResultModel<PageInfo<ShortVideoResponse>> queryPage(@RequestBody @Valid ShortVideoQuery request){
        log.info("queryPage:{},{}",request,request.getId());
        return shortVideoService.queryByList(request);
    }

    @PostMapping("switchVideo")
    public ResultModel<Boolean> switchVideo(@RequestBody @Valid SwitchVideoForm request){
        log.info("switchVideo:{}",request);
        return shortVideoService.switchVideo(request);
    }


}
